<?php

use Illuminate\Http\Request;

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It is a breeze. Simply tell Lumen the URIs it should respond to
| and give it the Closure to call when that URI is requested.
|
*/


$router->get('/', function () use ($router) {
    return '农乎';
});

$router->options('{path:.*}', function () {
    return response('', 200);
});

//小程序接口
$router->group(['middleware' => ['auth'],'prefix' => 'api', 'namespace' => 'Api'], function () use ($router) {

    $router->get('/order_list', 'OrderController@orderList');//订单列表
    $router->post('/buy_now', 'OrderController@buyNow');//立刻购买
    $router->get('/orders/confirm', 'OrderController@confirmOrder');//确认订单

    $router->post('confirm/receipt', 'OrderController@confirmReceipt');//订单列表确认订单

    $router->post('wechat/payment', 'OrderController@wechatPayment'); //微信支付

    $router->get('order/{id}','OrderController@orderDetails');//订单详情
    $router->post('order/comment', 'OrderController@commentOrder');//评论
    $router->get('more/comment', 'OrderController@moreComment');//更多评论
    $router->get('my/comment', 'OrderController@myComment');//更多评论


    // 收货地址
    $router->get('/addresses', 'AddressController@list');
    $router->post('/addresses/create', 'AddressController@create');
    $router->post('/addresses/setAddressDefault', 'AddressController@setAddressDefault');
    $router->get('/addresses/delete/{id}', 'AddressController@delete');
    $router->post('/addresses/edit/{id}', 'AddressController@edit');
    $router->get('/addresses/{id}', 'AddressController@details');



    // 购物车
    $router->get('/shop_carts/list', 'ShopCartsController@list');
    $router->post('/shop_carts/create', 'ShopCartsController@create');
    $router->post('/shop_carts/add', 'ShopCartsController@add');
    $router->post('/shop_carts/subtract', 'ShopCartsController@subtract');
    $router->post('/shop_carts/create_order', 'CommodityController@createOrderByShopCart');
    $router->post('/shop_carts/delete/{id}', 'ShopCartsController@delete');

    // 拼团订单
    $router->get('/groupBuyOrder', 'UserController@groupBuyOrder');
    $router->get('/groupBuyOrderDetails/{id}', 'UserController@groupBuyOrderDetails');

    // 我的
    $router->get('/aboutUs', 'UsersController@aboutUs');
    $router->post('user/getPhoneNumber', 'UserController@getPhoneNumber');


    $router->options('{path:.*}', function () {
//        header('Access-Control-Allow-Origin:*');
//        header('Access-Control-Allow-Methods:OPTIONS,POST,GET,PUT,DELETE');
//        header('Access-Control-Allow-Headers:requesttype,x-requested-with,content-type,x-csrf-token,x-csrf-token,x-requested-with,origin,x-custom-header');
        return response('', 200);
    });

});

/**
 * 没有auth验证的路由
 */
$router->group(['prefix' => 'api', 'namespace' => 'Api'], function () use ($router) {
    $router->get('login', 'UserController@login');
    $router->get('/home_icon', 'HomeController@homeIcon');//首页icon第一排
    $router->get('/home_column', 'HomeController@homeColumn');//首页分类版块
    $router->get('/home_swiper', 'HomeController@homeSwiper');//轮播


    $router->get('/goods_class', 'CommodityController@goodsClass');//分类
    $router->get('/goods_detail', 'CommodityController@goodsDetail');//详情
    $router->get('/groupbuy_list', 'CommodityController@groupBuyCommodityList');//首页拼团列表
    $router->get('/groupbuy_area', 'CommodityController@groupBuyArea');//拼团区
    $router->get('/groupbuy_list/{id}', 'CommodityController@groupBuyList');//详情

    $router->post('order/comment', 'OrderController@commentOrder');//评论
    $router->get('more/comment', 'OrderController@moreComment');//更多评论
    $router->get('my/comment', 'OrderController@myComment');//更多评论


    //售后
    $router->post('/after/refund', 'AftermarketController@refund');
    $router->post('/after/rejected', 'AftermarketController@rejected');

    // 我的
    $router->get('/aboutUs','UsersController@aboutUs');

    // 支付回调
    $router->get('payment/shoppingCallBack', 'NotifyController@shoppingCallBack');
    $router->post('payment/shoppingCallBack', 'NotifyController@shoppingCallBack');

});

//后台
$router->group(['prefix' => 'admin', 'namespace' => 'Admin'], function () use ($router) {
});
//商户端
$router->group(['prefix' => 'business', 'namespace' => 'Business'], function () use ($router) {
    $router->post('/sendsms', 'AdminUserController@sendSms');//sms
    $router->post('/register', 'AdminUserController@register');//注册
    $router->post('/login', 'AdminUserController@login');//登陆
//    $router->post('/dingding', 'AdminUserController@dingding');
    $router->post('/create/shop', 'AdminUserController@createShop');
    $router->get('/goods_class', 'CommodityController@goodsClass');


    $router->get('/order_list', 'OrderController@orderList');
    $router->get('/express', 'OrderController@express');
    $router->post('order/send', 'OrderController@send');



});


$router->group(['namespace' => 'Api'], function () use ($router) {
    $router->post('/upload', 'UploadController@upload');//图片上传
});






